Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

460
Visualizações
React.Lazy usage throws "Expression produces a union type that is too complex to represent"

I am trying to develop a simple application with two different components. The main one uses React.lazy to get the other component and wraps it inside a React.Suspense element. But there is a super weird error in this simple example and a more abnormal hacky solution.

The error is: Expression produces a union type that is too complex to represent

The source code is below. And I also created a repository that you can easily repeat the error yourself.

App.tsx contents

import React from "react"
import ReactDom from "react-dom"

const Fr = React.lazy(
    () => import('./Fragment')
);

// Uncomment this line below, then it compiles without any errors
// const dummy = <Fr />

const Main = () => (
    <div>
        <React.Suspense fallback={"Loading"}>
            <div>
                <Fr/> {/* Error:  Expression produces a union type that is too complex to represent */}
            </div>
        </React.Suspense>
    </div>
)

// @ts-ignore
ReactDom.render(<Main/>, document.body);

As you can see App.tsx imports ./Fragment with React.lazy. And when using the Fr component, typescript throws the error.

Fragment.tsx contents

import * as React from "react"

const Fragment = () => (
    <div>
        Fragment
    </div>
)

export default Fragment

When using Typescript 4.1.2, it works without any error, but in 4.5.2, it is not.

Weird Solution

When you uncomment the dummy assignment const dummy = <Fr />, it works without any problem.

Now I am wondering what is the actual problem here and why the dummy assignment solves it?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda